﻿using KC.DataAccess.Account;
using KC.DataAccess.Account.Repository;
using KC.Domain.Core.EFRepository;
using KC.Domain.Core.IRepository;
using KC.Framework.Base;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;

namespace KC.Service.Account
{
    public static class DependencyInjectUtil
    {
        public static void InjectService(IServiceCollection services)
        {
            services
                //.AddEntityFrameworkSqlServer()
                .AddDbContext<ComAccountContext>(
                    options => 
                        options.UseSqlServer(GlobalConfig.DatabaseConnectionString), ServiceLifetime.Transient, ServiceLifetime.Transient);

            services.AddTransient(typeof(EFUnitOfWorkContextBase), typeof(ComAccountUnitOfWorkContext));

            services.AddTransient(typeof(IDbRepository<>), typeof(CommonEFRepository<>));
            services.AddTransient(typeof(IDbTreeRepository<>), typeof(CommonEFTreeRepository<>));

            services.AddTransient<IUserRepository, UserRepository>();
            services.AddTransient<IRoleRepository, AspNetRoleRepository>();
            services.AddTransient<IMenuNodeRepository, MenuNodeRepository>();
            services.AddTransient<IPermissionRepository, PermissionRepository>();
            services.AddTransient<IOrganizationRepository, OrganizationRepository>();
            
            services.AddTransient<IAccountService, AccountService>();
            services.AddTransient<ISysManageService, SysManageService>();
            services.AddTransient<IRoleService, RoleService>();
            services.AddTransient<IMenuService, MenuService>();
            services.AddTransient<IPermissionService, PermissionService>();
        }
    }
}
